<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="学生姓名" prop="studentName">
            <el-input v-model="form.studentName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="姓别" prop="studentSex">
            <el-select v-model="form.studentSex" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.sex"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="学生出生日期" prop="studentBirthday">
            <el-date-picker v-model="form.studentBirthday" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学生国家">
            <el-input v-model="form.studentNation" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学生籍贯">
            <el-input v-model="form.studentNativePlace" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学生电话">
            <el-input v-model="form.studentPhone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学生邮箱">
            <el-input v-model="form.studentEmail" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学生住址">
            <el-input v-model="form.studentAddr" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人1姓名">
            <el-input v-model="form.guardianFirstName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人1关系">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="监护人1电话">
            <el-input v-model="form.guardianFirstPhone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人1邮箱">
            <el-input v-model="form.guardianFirstEmail" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人1住址">
            <el-input v-model="form.guardianFirstAddr" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人2姓名">
            <el-input v-model="form.guardianSecondName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人2关系">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="监护人2电话">
            <el-input v-model="form.guardianSecondPhone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人2邮箱">
            <el-input v-model="form.guardianSecondEmail" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监护人2住址">
            <el-input v-model="form.guardianSecondAddr" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="studentName" label="学生姓名" />
        <el-table-column prop="studentSex" label="姓别">
          <template slot-scope="scope">
            {{ dict.label.sex[scope.row.studentSex] }}
          </template>
        </el-table-column>
        <el-table-column prop="studentBirthday" label="学生出生日期" />
        <el-table-column prop="studentNation" label="学生国家" />
        <el-table-column prop="studentNativePlace" label="学生籍贯" />
        <el-table-column prop="studentPhone" label="学生电话" />
        <el-table-column prop="studentEmail" label="学生邮箱" />
        <el-table-column prop="studentAddr" label="学生住址" />
        <el-table-column v-if="checkPer(['admin','schRegistratrion:edit','schRegistratrion:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSchRegistratrion from '@/api/schRegistratrion'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { regId: null, studentName: null, studentSex: null, studentBirthday: null, studentNation: null, studentNativePlace: null, studentPhone: null, studentEmail: null, studentAddr: null, guardianFirstName: null, guardianFirstRelationship: null, guardianFirstPhone: null, guardianFirstEmail: null, guardianFirstAddr: null, guardianSecondName: null, guardianSecondRelationship: null, guardianSecondPhone: null, guardianSecondEmail: null, guardianSecondAddr: null, state: null, delFlag: null }
export default {
  name: 'SchRegistratrion',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['sex'],
  cruds() {
    return CRUD({ title: '入学申请', url: 'api/schRegistratrion', idField: 'regId', sort: 'regId,desc', crudMethod: { ...crudSchRegistratrion }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'schRegistratrion:add'],
        edit: ['admin', 'schRegistratrion:edit'],
        del: ['admin', 'schRegistratrion:del']
      },
      rules: {
        regId: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        studentName: [
          { required: true, message: '学生姓名不能为空', trigger: 'blur' }
        ],
        studentSex: [
          { required: true, message: '姓别不能为空', trigger: 'blur' }
        ],
        studentBirthday: [
          { required: true, message: '学生出生日期不能为空', trigger: 'blur' }
        ]
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
